/* This file was generated with JastAdd2 (http://jastadd.org) version R20121112 (r872) */
package parser;

import semanticlib.SymbolTable;
/**
 * @production Decl : {@link Stmt} ::= <span class="component">{@link IdDecl}</span> <span class="component">[{@link Exp}]</span>;
 * @ast node
 * @declaredat /h/d1/l/int13mka/workspace/CalcAnalysis/specification/MiniP.ast:9
 */
public class Decl extends Stmt implements Cloneable {
  /**
   * @apilevel low-level
   */
  public void flushCache() {
    super.flushCache();
  }
  /**
   * @apilevel internal
   */
  public void flushCollectionCache() {
    super.flushCollectionCache();
  }
  /**
   * @apilevel internal
   */
  @SuppressWarnings({"unchecked", "cast"})
  public Decl clone() throws CloneNotSupportedException {
    Decl node = (Decl)super.clone();
    return node;
  }
  /**
   * @apilevel internal
   */
  @SuppressWarnings({"unchecked", "cast"})
  public Decl copy() {
      try {
        Decl node = (Decl)clone();
        if(children != null) node.children = (ASTNode[])children.clone();
        return node;
      } catch (CloneNotSupportedException e) {
      }
      System.err.println("Error: Could not clone node of type " + getClass().getName() + "!");
      return null;
  }
  /**
   * Create a deep copy of the AST subtree at this node.
   * The copy is dangling, i.e. has no parent.
   * @return dangling copy of the subtree at this node
   * @apilevel low-level
   */
  @SuppressWarnings({"unchecked", "cast"})
  public Decl fullCopy() {
    try {
      Decl tree = (Decl) clone();
      tree.setParent(null);// make dangling
      if (children != null) {
        tree.children = new ASTNode[children.length];
        for (int i = 0; i < children.length; ++i) {
          if (children[i] == null) {
            tree.children[i] = null;
          } else {
            tree.children[i] = ((ASTNode) children[i]).fullCopy();
            ((ASTNode) tree.children[i]).setParent(tree);
          }
        }
      }
      return tree;
    } catch (CloneNotSupportedException e) {
      throw new Error("Error: clone not supported for " +
        getClass().getName());
    }
  }
  /**
   * @ast method 
   * @aspect NameAnalysis
   * @declaredat /h/d1/l/int13mka/workspace/CalcAnalysis/specification/NameAnalysis.jadd:50
   */
  void analyze(SymbolTable table){
		getIdDecl().addDecl(table);
	}
  /**
   * @ast method 
   * 
   */
  public Decl(int i) {
    super(i);
  }
  /**
   * @ast method 
   * 
   */
  public Decl(MiniP p, int i) {
    this(i);
    parser = p;
  }
  /**
   * @ast method 
   * 
   */
  public Decl() {
    this(0);

    setChild(new Opt(), 1);

  }
  /**
   * @ast method 
   * 
   */
  public Decl(IdDecl p0, Opt<Exp> p1) {
    setChild(p0, 0);
    setChild(p1, 1);
  }
  /**
   * @ast method 
   * 
   */
  public void dumpTree(String indent, java.io.PrintStream pStream) {
    pStream.println(indent + "Decl");
        String childIndent = indent + "  ";
    for(int i = 0; i < getNumChild(); i++)
      getChild(i).dumpTree(childIndent, pStream);
  }
  /**
   * @ast method 
   * 
   */
  public Object jjtAccept(MiniPVisitor visitor, Object data) {
    return visitor.visit(this, data);
  }
  /**
   * @ast method 
   * 
   */
  public void jjtAddChild(Node n, int i) {
    checkChild(n, i);
    super.jjtAddChild(n, i);
}
  /**
   * @ast method 
   * 
   */
  public void checkChild(Node n, int i) {
    if(i == 0 && !(n instanceof IdDecl))  throw new Error("Child number 0 of Decl has the type " + n.getClass().getName() + " which is not an instance of IdDecl");
    if(i == 1) {
      if(!(n instanceof Opt))
        throw new Error("Child number 1 of Decl has the type " + n.getClass().getName() + " which is not an instance of Opt");
      if(((Opt)n).getNumChildNoTransform() != 0 && !(((Opt)n).getChildNoTransform(0) instanceof Exp))
        throw new Error("Optional Exp has the type " + ((Opt)n).getChildNoTransform(0).getClass().getName() + " which is not an instance of Exp");
    }
  }
  /**
   * @apilevel low-level
   * @ast method 
   * 
   */
  public int getNumChild() {
    return 2;
  }
  /**
   * Replaces the IdDecl child.
   * @param node The new node to replace the IdDecl child.
   * @apilevel high-level
   * @ast method 
   * 
   */
  public void setIdDecl(IdDecl node) {
    setChild(node, 0);
  }
  /**
   * Retrieves the IdDecl child.
   * @return The current node used as the IdDecl child.
   * @apilevel high-level
   * @ast method 
   * 
   */
  public IdDecl getIdDecl() {
    return (IdDecl)getChild(0);
  }
  /**
   * Retrieves the IdDecl child.
   * <p><em>This method does not invoke AST transformations.</em></p>
   * @return The current node used as the IdDecl child.
   * @apilevel low-level
   * @ast method 
   * 
   */
  public IdDecl getIdDeclNoTransform() {
    return (IdDecl)getChildNoTransform(0);
  }
  /**
   * Replaces the optional node for the Exp child. This is the {@code Opt} node containing the child Exp, not the actual child!
   * @param opt The new node to be used as the optional node for the Exp child.
   * @apilevel low-level
   * @ast method 
   * 
   */
  public void setExpOpt(Opt<Exp> opt) {
    setChild(opt, 1);
  }
  /**
   * Check whether the optional Exp child exists.
   * @return {@code true} if the optional Exp child exists, {@code false} if it does not.
   * @apilevel high-level
   * @ast method 
   * 
   */
  public boolean hasExp() {
    return getExpOpt().getNumChild() != 0;
  }
  /**
   * Retrieves the (optional) Exp child.
   * @return The Exp child, if it exists. Returns {@code null} otherwise.
   * @apilevel low-level
   * @ast method 
   * 
   */
  @SuppressWarnings({"unchecked", "cast"})
  public Exp getExp() {
    return (Exp)getExpOpt().getChild(0);
  }
  /**
   * Replaces the (optional) Exp child.
   * @param node The new node to be used as the Exp child.
   * @apilevel high-level
   * @ast method 
   * 
   */
  public void setExp(Exp node) {
    getExpOpt().setChild(node, 0);
  }
  /**
   * Retrieves the optional node for the Exp child. This is the {@code Opt} node containing the child Exp, not the actual child!
   * @return The optional node for child the Exp child.
   * @apilevel low-level
   * @ast method 
   * 
   */
  @SuppressWarnings({"unchecked", "cast"})
  public Opt<Exp> getExpOpt() {
    return (Opt<Exp>)getChild(1);
  }
  /**
   * Retrieves the optional node for child Exp. This is the {@code Opt} node containing the child Exp, not the actual child!
   * <p><em>This method does not invoke AST transformations.</em></p>
   * @return The optional node for child Exp.
   * @apilevel low-level
   * @ast method 
   * 
   */
  @SuppressWarnings({"unchecked", "cast"})
  public Opt<Exp> getExpOptNoTransform() {
    return (Opt<Exp>)getChildNoTransform(1);
  }
}
